package tbdp.tool.config;

import java.util.Map;

import tbdp.tool.common.ToString;

/**
 * @author xbkaishui
 * @version $Id: AbstractConfig.java, v 0.1 2017-06-17 下午3:51 xbkaishui Exp $$
 */
public class AbstractConfig extends ToString {

    private String name;
    private String type;

    protected Map<String, Object> config;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Map<String, Object> getConfig() {
        return config;
    }

    public void setConfig(Map<String, Object> config) {
        this.config = config;
    }

    public Object getConfigProp(String key) {
        return config.get(key);
    }

    public String getConfigPropAsString(String key) {
        Object val = config.get(key);
        if (val == null) {
            return null;
        }
        return val.toString();
    }

    public String getConfigPropAsString(String key, String def) {
        String value = getConfigPropAsString(key);
        if (value == null) {
            return def;
        }
        return value;
    }
}
